package servlet;

import dao.IUserDao;
import dao.UserDaoImp;
import service.IUserService;
import service.imp.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    IUserService dao=new UserServiceImp();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String userName = req.getParameter("userName");
        String password = req.getParameter("password");
        if (dao.login(userName,password)!=null) {
            resp.getWriter().print("hello," + userName + ",登录成功");
        } else {
            resp.getWriter().print("登录失败");
        }
    }
}